import promisify from './promisify.js';
import { http } from '@/plugins/luch-request/config.js';

/**
 * 获取token
 */
const getToken = () => {
    const login = promisify(uni.login);
    // #ifndef H5
    return login().then(resCode => {
        return http.post(feConfig.token, {
            data: {
                grant_type: 'wx_login',
                username: feConfig.appid,
                password: resCode.code
            },
            header: {
                'Content-Type': 'application/x-www-form-urlencoded',
                Authorization: 'Basic ' + feConfig.client_base64
            }
        });
    });
    // #endif
};

module.exports = {
    getToken
};
